package com.kymatrix.kycarbon.xsmd.common.business.common;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.ArrayList;
import java.util.List;
import lombok.Data;

@ApiModel("分页请求响应")
@Data
public class PageResp<T> {
    
    @ApiModelProperty("数据列表")
    private List<T> list = new ArrayList<>();
    
    @ApiModelProperty("总条数")
    private Long total = 0L;

    /**
     * 构造返回
     */
    public static <T> PageResp<T> build(Page<T> page) {
        PageResp<T> pageResp = new PageResp<>();
        pageResp.setList(page.getRecords());
        pageResp.setTotal(page.getTotal());
        return pageResp;
    }

    public PageResp(List<T> list, Long total) {
        this.list = list;
        this.total = total;
    }

    public PageResp() {
    }
}
